package com.itheima.exception;

import com.itheima.common.Code;
import com.itheima.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.concurrent.CompletionException;

/**
 * @Author: yangshuai
 * @Desc: 全局异常处理器
 * @Date: 2022-06-05 14:27:09
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception ex){
        String errMsg = ex.getMessage();
        log.error(ex.getMessage());
        return new Result(Code.ERROR,errMsg);
    }
}
